package tech.aistar.day12;

import java.math.BigDecimal;
import java.math.BigInteger;

/**
 * 本类用来演示:
 *
 * @author: success
 * @date: 2021/3/23 9:29 上午
 */
public class BigIntegerDemo {
    public static void main(String[] args) {
        System.out.println(fac(6));

        //BigDecimal - 处理java小数在计算的时候会有精度的溢出
        //System.out.println(0.1+0.2);
        BigDecimal bi01 = new BigDecimal("0.1");
        BigDecimal bi02 = new BigDecimal("0.2");
        System.out.println(bi01.add(bi02));//0.3
    }

    public static BigInteger fac(int n){
        if(n==1)
            return BigInteger.ONE;
        //将int->BigInteger类型
        BigInteger bi = new BigInteger(String.valueOf(n));
        return bi.multiply(fac(n-1));
    }
}
